package com.tudouji.project.d3.controller;

import java.util.List;

import com.tudouji.project.d3.domain.D3ToSellform;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.d3.domain.D3ProToSp;
import com.tudouji.project.d3.service.ID3ProToSpService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 商品对应关系Controller
 * 
 * @author tudouji
 * @date 2023-04-10
 */
@RestController
@RequestMapping("/d3/protosp")
public class D3ProToSpController extends BaseController
{
    @Autowired
    private ID3ProToSpService d3ProToSpService;

    /**
     * 查询商品对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('d3:protosp:list')")
    @GetMapping("/list")
    public TableDataInfo list(D3ProToSp d3ProToSp)
    {
        startPage();
        List<D3ProToSp> list = d3ProToSpService.selectD3ProToSpList(d3ProToSp);
        return getDataTable(list);
    }

    /**
     * 导出商品对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('d3:protosp:export')")
    @Log(title = "商品对应关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(D3ProToSp d3ProToSp)
    {
        List<D3ProToSp> list = d3ProToSpService.selectD3ProToSpList(d3ProToSp);
        ExcelUtil<D3ProToSp> util = new ExcelUtil<D3ProToSp>(D3ProToSp.class);
        return util.exportExcel(list, "protosp");
    }

    /**
     * 获取商品对应关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('d3:protosp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(d3ProToSpService.selectD3ProToSpById(id));
    }


    /**
     * 新增平台订单中间
     */
    @PostMapping("/addAll")
    public AjaxResult addAll(@RequestBody List<D3ProToSp> d3ProToSps)
    {
        return d3ProToSpService.insertD3ProToSpAll(d3ProToSps);
    }
    /**
     * 新增商品对应关系
     */
    @PreAuthorize("@ss.hasPermi('d3:protosp:add')")
    @Log(title = "商品对应关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody D3ProToSp d3ProToSp)
    {
        return toAjax(d3ProToSpService.insertD3ProToSp(d3ProToSp));
    }

    /**
     * 修改商品对应关系
     */
    @PreAuthorize("@ss.hasPermi('d3:protosp:edit')")
    @Log(title = "商品对应关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody D3ProToSp d3ProToSp)
    {
        return toAjax(d3ProToSpService.updateD3ProToSp(d3ProToSp));
    }

    /**
     * 删除商品对应关系
     */
    @PreAuthorize("@ss.hasPermi('d3:protosp:remove')")
    @Log(title = "商品对应关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(d3ProToSpService.deleteD3ProToSpByIds(ids));
    }
}
